home *** CD-ROM | disk | FTP | other *** search
/ LineOne ISP Sign-Up 5 / LineOne.iso / assets / cxt / scripts / parentScripts.cst / 00073_cursorService parent.ls < prev    next >
Encoding:
Text File  |  2001-01-27  |  5.1 KB  |  180 lines

  1. -- 2000.02.26
  2. -- Clive Green <clivegreen@atlas.co.uk>
  3.  
  4. ------------------------------------------------------------------------------------------------------
  5.  
  6. -- this offers rudimentary cursor control, using static 1-bit bitmap custom cursors.
  7.  
  8. ------------------------------------------------------------------------------------------------------
  9.  
  10. -- declare properties:
  11. property main            -- main code directory object
  12. property cursorList      -- a runtime-compiled #proplist of known custom cursors
  13.  
  14. ------------------------------------------------------------------------------------------------------
  15.  
  16. on new me,L
  17.   
  18.   -- (1) extract and check arguments:
  19.   
  20.   -- check for a parameter list:
  21.   if ilk(L) <> #propList then return [#error:#noParamListSupplied, #msg:"cursorService:new"]
  22.   
  23.   -- a reference to the parent codebase is REQUIRED:
  24.   main = L[#main]
  25.   if (ilk(main) <> #instance) then return ┬¼
  26.   [#error:#noMainObjectSupplied, #msg:"cursorService:new"]
  27.   
  28.   --------------------
  29.   
  30.   -- (2) compile a list of known custom cursors:
  31.   o = me.compileCursors()
  32.   if (ilk(o) <> #instance) then return o
  33.   
  34.   -- pass back my address:
  35.   return me
  36.   
  37.   ----------------------------------------------------------------------------------------------------
  38.   
  39. on compileCursors me
  40.   
  41.   -- This simply compiles a list of custom 1-bit cursors by examining the contents of an
  42.   -- attached castlib called "cursors". 1-bit cursors (currently) avoid the flicker problem
  43.   -- encountered when using 'cursor asset' cursors over Flash 4 movie sprites within a D7 movie.
  44.   
  45.   -- Each cursor is stored as a linear list [] containing a cursor and (optionally) a mask
  46.   -- castmember number, and each cursor is uniquely named.  
  47.   
  48.   -- Note that the preparation and naming of cursor graphics is important here ; a cursor called
  49.   -- #myArrow would become available to the programme only if there exists a 1-bit graphic castmember
  50.   -- called "myArrow cursor" within the "cursors" castlibrary (an optional member called "myArrow
  51.   -- mask" would be used as the cursor mask.)
  52.   
  53.   --------------------
  54.   
  55.   -- (1) first declare all literals:
  56.   
  57.   -- what cursor castmember name suffixes are used?
  58.   suffixList = [:]
  59.   suffixList[#cursor] = "cursor"
  60.   suffixList[#mask]   = "mask"
  61.   
  62.   -- and in what castlibrary?
  63.   cursorLibName = "cursors"
  64.   c = castlib(cursorLibName).number
  65.   
  66.   --------------------
  67.   
  68.   -- initialise the storage listing:
  69.   cursorList = [:]
  70.   
  71.   -- gather 1-bit cursor information:
  72.   repeat with i = 1 to the number of members of castlib c
  73.     
  74.     -- examine each member's type - we want 1-bit cursor bitmap graphics ONLY:
  75.     n = member(i,c).number
  76.     t = member(n).type
  77.     
  78.     if t <> #bitmap then next repeat
  79.     if member(n).depth > 8 then next repeat
  80.     
  81.     -- pull the cursor's prefix and suffix strings:
  82.     x = member(n).name
  83.     a = symbol(word 1 of x)
  84.     b = the last word of x
  85.     
  86.     -- is b a recognised suffix string?
  87.     z = getPos(suffixList,b)
  88.     if not z then next repeat
  89.     
  90.     -- what is the storage #label for an element with this suffix?
  91.     z = getPropAt(suffixList,z)
  92.     
  93.     -- does a listed entry for cursor (a) already exist?
  94.     L = cursorList[a]
  95.     if not listP(L) then
  96.       
  97.       -- create a new storage listing for cursor a:
  98.       L = [:]
  99.       cursorList[a] = L
  100.       
  101.     end if
  102.     
  103.     -- now store the member number n using the suffix z:
  104.     L[z] = n
  105.     
  106.   end repeat
  107.   
  108.   --------------------
  109.   
  110.   -- now convert the compiled cursor listing into a series of listed cursor/mask pairs:
  111.   repeat with i = 1 to count(cursorList)
  112.     
  113.     -- get the ith list of cursor bitmaps:
  114.     L1 = cursorList[i]
  115.     
  116.     -- create a linear storage list to hold extracted bitmap members:
  117.     L2 = []
  118.     
  119.     -- look for the REQUIRED #cursor element:
  120.     c = L1[#cursor]
  121.     if not integerP(c) then
  122.       
  123.       -- set the data list for the ith cursor to an empty linear list:
  124.       cursorList[i] = []
  125.       next repeat
  126.       
  127.     end if
  128.     
  129.     -- store this element:
  130.     add L2,c
  131.     
  132.     -- look for an optional #mask element:
  133.     m = L1[#mask]
  134.     if integerP(m) then add L2,m
  135.     
  136.     -- replace the ith list cursor data with a validated and ordered linear list:
  137.     cursorList[i] = L2
  138.     
  139.   end repeat
  140.   
  141.   -- flag success to caller:
  142.   return me
  143.   
  144.   ----------------------------------------------------------------------------------------------------
  145.   
  146. on setCursor me,L
  147.   
  148.   -- extract a valid cursor ID:
  149.   if ilk(L) <> #propList then return 0
  150.   
  151.   c = L[#cursorID]
  152.   if not symbolP(c) then return 0
  153.   
  154.   -- try to obtain a recognised cursor:
  155.   cL = cursorList[c]
  156.   if not listP(cL) then return 0
  157.   if not count(cL) then return 0
  158.   
  159.   --------------------
  160.   
  161.   -- cL will contain either one or two bitmap member numbers, with the foreground element always
  162.   -- listed first:
  163.   
  164.   -- set a valid cursor:
  165.   cursor cL
  166.   
  167.   -- flag success:
  168.   return 1
  169.   
  170.   ----------------------------------------------------------------------------------------------------
  171.   
  172. on clearCursor me
  173.   
  174.   -- unconditionally reset:
  175.   cursor 0
  176.   
  177.   -- flag success:
  178.   return 1
  179.   
  180.   ----------------------------------------------------------------------------------------------------